Skip to content

Lag label#228

Open
danshapero wants to merge 15 commits into
firedrakeproject:masterfrom
danshapero:lag-label
Open

Lag label#228
danshapero wants to merge 15 commits into
firedrakeproject:masterfrom
danshapero:lag-label

Conversation

@danshapero
Copy link
Copy Markdown
Collaborator

Resolves #221. This PR adds a function lag which labels a single expression in a form for holding back to the start of a timestep. As @pbrubeck thought, implementing it amounted to modifying irksome.tools.replace. I added a test based on lagging the conductivity in the Stefan problem. Without lagging, that fails because of the conditional.

In addition to giving you an escape hatch, you can use lagging to define nonlinear preconditioners. I have a demo of this for the Allen-Cahn equation coded up just using petsc4py which I think is pretty compelling. @JHopeCollins and I are working on getting AuxiliaryOperatorSNES merged into Firedrake: firedrakeproject/firedrake#5119. Once that's merged I can write an Irksome demo showing that off, either in this PR or a separate one.

@danshapero danshapero requested a review from pbrubeck May 15, 2026 14:13
Comment thread irksome/tools.py Outdated
Comment thread irksome/tools.py
@pbrubeck
Copy link
Copy Markdown
Collaborator

pbrubeck commented May 15, 2026

I just noticed that #227 might potentially be useful for similar purposes.

Fp could then be a bilinear form a(u0; u, v) depending on the frozen state u0, u is a TrialFunction, and the only time derivative we expect is Dt(u). We don't differentiate wrt. u0 to form the preconditioner, nor apply replacement rules involving u0 in this setting.

I think it's fine to support both modes.

Comment thread tests/test_lag.py
final_time = 10.0
num_steps = int(final_time / float(dt))
for step in range(num_steps):
stepper.advance()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an assertion here?

Comment thread irksome/tools.py Outdated
Comment thread irksome/tools.py
Comment thread irksome/tools.py Outdated
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com>
Comment thread irksome/tools.py Outdated
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com>
Comment thread irksome/tools.py Outdated
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com>
Comment thread irksome/ufl/deriv.py
Comment on lines +88 to +98
# A :class:`ufl.Label` to mark nodes that are only evaluated at the start of
# the timestep.
lag_label = Label()


def lag(expr):
"""Mark a sub-expression to be evaluated only at the start of the
timestep during the implicit solve."""
return Variable(expr, lag_label)


Copy link
Copy Markdown
Collaborator

@pbrubeck pbrubeck May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file does not seem the right place to define this. I think we should be creating a new file.

Comment thread irksome/tools.py Outdated
Comment thread irksome/tools.py
Comment thread irksome/tools.py Outdated
pbrubeck added 2 commits May 18, 2026 10:12
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com>
Comment thread irksome/tools.py
Comment thread irksome/tools.py Outdated
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com>
Comment thread irksome/tools.py Outdated
Comment thread irksome/tools.py Outdated
Comment thread irksome/tools.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lagging terms

2 participants